package com.datagateway.component;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 数据格式转换管理器
 * 负责实现多种数据格式之间的转换，包括JSON、XML、CSV、YAML等
 * 
 * @author Data Gateway Team
 * @version 1.0.0
 */
@Component
public class DataFormatConverter {

    private static final Logger logger = LoggerFactory.getLogger(DataFormatConverter.class);

    @Autowired
    private AlertManager alertManager;

    /**
     * 转换统计
     */
    private final AtomicLong totalConversions = new AtomicLong(0);
    private final AtomicLong totalSuccessfulConversions = new AtomicLong(0);
    private final AtomicLong totalFailedConversions = new AtomicLong(0);
    private final AtomicLong totalBytesProcessed = new AtomicLong(0);

    /**
     * 转换配置
     */
    private boolean conversionEnabled = true;
    private String defaultInputFormat = "JSON";
    private String defaultOutputFormat = "JSON";
    private boolean prettyPrint = true;
    private boolean validateInput = true;
    private boolean validateOutput = true;
    private int maxConversionSize = 10 * 1024 * 1024; // 10MB

    /**
     * 对象映射器
     */
    private final ObjectMapper jsonMapper = new ObjectMapper();

    /**
     * 转换器缓存
     */
    private final Map<String, FormatConverter> converters = new ConcurrentHashMap<>();
    private final Map<String, ConversionConfig> conversionConfigs = new ConcurrentHashMap<>();

    /**
     * 初始化数据格式转换器
     */
    public void initialize() {
        try {
            // 配置对象映射器
            configureObjectMappers();
            
            // 注册默认转换器
            registerDefaultConverters();
            
            logger.info("数据格式转换器初始化成功");
            
        } catch (Exception e) {
            logger.error("数据格式转换器初始化失败", e);
            alertManager.sendSystemErrorAlert("数据格式转换器初始化失败", e.getMessage());
        }
    }

    /**
     * 转换数据格式
     * 
     * @param data 原始数据
     * @param inputFormat 输入格式
     * @param outputFormat 输出格式
     * @return 转换后的数据
     */
    public ConversionResult convert(String data, String inputFormat, String outputFormat) {
        if (!conversionEnabled) {
            return new ConversionResult(data, false, "CONVERSION_DISABLED", "数据格式转换已禁用");
        }

        try {
            totalConversions.incrementAndGet();
            totalBytesProcessed.addAndGet(data.getBytes().length);
            
            // 验证输入数据大小
            if (data.length() > maxConversionSize) {
                totalFailedConversions.incrementAndGet();
                return new ConversionResult(null, false, "SIZE_EXCEEDED", 
                    "数据大小超过限制: " + data.length() + " > " + maxConversionSize);
            }
            
            // 获取转换器
            String converterKey = inputFormat.toUpperCase() + "_TO_" + outputFormat.toUpperCase();
            FormatConverter converter = converters.get(converterKey);
            
            if (converter == null) {
                totalFailedConversions.incrementAndGet();
                return new ConversionResult(null, false, "CONVERTER_NOT_FOUND", 
                    "未找到转换器: " + converterKey);
            }
            
            // 执行转换
            String result = converter.convert(data);
            
            totalSuccessfulConversions.incrementAndGet();
            return new ConversionResult(result, true, "SUCCESS", null);
            
        } catch (Exception e) {
            totalFailedConversions.incrementAndGet();
            logger.error("数据格式转换失败: {} -> {}", inputFormat, outputFormat, e);
            return new ConversionResult(null, false, "CONVERSION_ERROR", e.getMessage());
        }
    }

    /**
     * 转换数据格式（使用默认配置）
     * 
     * @param data 原始数据
     * @param outputFormat 输出格式
     * @return 转换后的数据
     */
    public ConversionResult convert(String data, String outputFormat) {
        return convert(data, defaultInputFormat, outputFormat);
    }

    /**
     * 批量转换数据格式
     * 
     * @param dataList 数据列表
     * @param inputFormat 输入格式
     * @param outputFormat 输出格式
     * @return 转换结果列表
     */
    public List<ConversionResult> batchConvert(List<String> dataList, String inputFormat, String outputFormat) {
        List<ConversionResult> results = new ArrayList<>();
        
        for (String data : dataList) {
            results.add(convert(data, inputFormat, outputFormat));
        }
        
        return results;
    }

    /**
     * 验证数据格式
     * 
     * @param data 数据
     * @param format 格式
     * @return 验证结果
     */
    public ValidationResult validate(String data, String format) {
        try {
            switch (format.toUpperCase()) {
                case "JSON":
                    jsonMapper.readTree(data);
                    return new ValidationResult(true, "VALID", null);
                case "XML":
                    // 简单的XML验证
                    if (data.trim().startsWith("<") && data.trim().endsWith(">")) {
                        return new ValidationResult(true, "VALID", null);
                    } else {
                        return new ValidationResult(false, "INVALID", "XML格式无效");
                    }
                case "YAML":
                    // 简单的YAML验证
                    if (data.contains(":") || data.contains("-")) {
                        return new ValidationResult(true, "VALID", null);
                    } else {
                        return new ValidationResult(false, "INVALID", "YAML格式无效");
                    }
                case "CSV":
                    // CSV验证
                    if (data.contains(",") || data.contains("\n")) {
                        return new ValidationResult(true, "VALID", null);
                    } else {
                        return new ValidationResult(false, "INVALID", "CSV格式无效");
                    }
                default:
                    return new ValidationResult(false, "UNSUPPORTED", "不支持的格式: " + format);
            }
        } catch (Exception e) {
            return new ValidationResult(false, "INVALID", e.getMessage());
        }
    }

    /**
     * 获取支持的格式列表
     * 
     * @return 支持的格式列表
     */
    public List<String> getSupportedFormats() {
        return Arrays.asList("JSON", "XML", "CSV", "YAML");
    }

    /**
     * 获取支持的转换器列表
     * 
     * @return 支持的转换器列表
     */
    public List<String> getSupportedConverters() {
        return new ArrayList<>(converters.keySet());
    }

    /**
     * 注册自定义转换器
     * 
     * @param key 转换器键
     * @param converter 转换器
     * @return 是否注册成功
     */
    public boolean registerConverter(String key, FormatConverter converter) {
        try {
            converters.put(key.toUpperCase(), converter);
            logger.info("自定义转换器注册成功: {}", key);
            return true;
        } catch (Exception e) {
            logger.error("注册自定义转换器失败: {}", key, e);
            return false;
        }
    }

    /**
     * 删除转换器
     * 
     * @param key 转换器键
     * @return 是否删除成功
     */
    public boolean removeConverter(String key) {
        try {
            FormatConverter removed = converters.remove(key.toUpperCase());
            if (removed != null) {
                logger.info("转换器删除成功: {}", key);
                return true;
            }
            return false;
        } catch (Exception e) {
            logger.error("删除转换器失败: {}", key, e);
            return false;
        }
    }

    /**
     * 获取转换统计信息
     * 
     * @return 统计信息
     */
    public ConversionStatistics getStatistics() {
        return new ConversionStatistics(
            totalConversions.get(),
            totalSuccessfulConversions.get(),
            totalFailedConversions.get(),
            totalBytesProcessed.get(),
            converters.size(),
            conversionConfigs.size(),
            conversionEnabled,
            defaultInputFormat,
            defaultOutputFormat,
            prettyPrint,
            validateInput,
            validateOutput,
            maxConversionSize,
            System.currentTimeMillis()
        );
    }

    /**
     * 设置转换配置
     * 
     * @param enabled 是否启用转换
     * @param defaultInputFormat 默认输入格式
     * @param defaultOutputFormat 默认输出格式
     * @param prettyPrint 是否美化输出
     * @param validateInput 是否验证输入
     * @param validateOutput 是否验证输出
     * @param maxConversionSize 最大转换大小
     */
    public void setConfiguration(boolean enabled, String defaultInputFormat, String defaultOutputFormat,
                               boolean prettyPrint, boolean validateInput, boolean validateOutput, int maxConversionSize) {
        this.conversionEnabled = enabled;
        this.defaultInputFormat = defaultInputFormat;
        this.defaultOutputFormat = defaultOutputFormat;
        this.prettyPrint = prettyPrint;
        this.validateInput = validateInput;
        this.validateOutput = validateOutput;
        this.maxConversionSize = maxConversionSize;
        
        logger.info("数据格式转换配置已更新: 启用={}, 默认输入格式={}, 默认输出格式={}, 美化输出={}, 验证输入={}, 验证输出={}, 最大转换大小={}", 
                   enabled, defaultInputFormat, defaultOutputFormat, prettyPrint, validateInput, validateOutput, maxConversionSize);
    }

    /**
     * 配置对象映射器
     */
    private void configureObjectMappers() {
        // 配置JSON映射器
        jsonMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        jsonMapper.configure(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    }

    /**
     * 注册默认转换器
     */
    private void registerDefaultConverters() {
        // JSON转换器
        converters.put("JSON_TO_JSON", new JsonToJsonConverter());
        converters.put("JSON_TO_XML", new JsonToXmlConverter());
        converters.put("JSON_TO_CSV", new JsonToCsvConverter());
        converters.put("JSON_TO_YAML", new JsonToYamlConverter());
        
        // XML转换器
        converters.put("XML_TO_JSON", new XmlToJsonConverter());
        converters.put("XML_TO_XML", new XmlToXmlConverter());
        converters.put("XML_TO_CSV", new XmlToCsvConverter());
        converters.put("XML_TO_YAML", new XmlToYamlConverter());
        
        // CSV转换器
        converters.put("CSV_TO_JSON", new CsvToJsonConverter());
        converters.put("CSV_TO_XML", new CsvToXmlConverter());
        converters.put("CSV_TO_CSV", new CsvToCsvConverter());
        converters.put("CSV_TO_YAML", new CsvToYamlConverter());
        
        // YAML转换器
        converters.put("YAML_TO_JSON", new YamlToJsonConverter());
        converters.put("YAML_TO_XML", new YamlToXmlConverter());
        converters.put("YAML_TO_CSV", new YamlToCsvConverter());
        converters.put("YAML_TO_YAML", new YamlToYamlConverter());
    }

    /**
     * 格式转换器接口
     */
    public interface FormatConverter {
        String convert(String data) throws Exception;
    }

    /**
     * JSON到JSON转换器
     */
    public class JsonToJsonConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            if (validateInput) {
                jsonMapper.readTree(data);
            }
            if (prettyPrint) {
                Object json = jsonMapper.readValue(data, Object.class);
                return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
            }
            return data;
        }
    }

    /**
     * JSON到XML转换器
     */
    public class JsonToXmlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            if (validateInput) {
                jsonMapper.readTree(data);
            }
            // 简化的JSON到XML转换
            Object json = jsonMapper.readValue(data, Object.class);
            return convertJsonToXml(json);
        }
        
        private String convertJsonToXml(Object obj) {
            if (obj instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, Object> map = (Map<String, Object>) obj;
                StringBuilder xml = new StringBuilder();
                xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n");
                for (Map.Entry<String, Object> entry : map.entrySet()) {
                    xml.append("  <").append(entry.getKey()).append(">");
                    xml.append(entry.getValue());
                    xml.append("</").append(entry.getKey()).append(">\n");
                }
                xml.append("</root>");
                return xml.toString();
            }
            return "<root>" + obj + "</root>";
        }
    }

    /**
     * JSON到CSV转换器
     */
    public class JsonToCsvConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            if (validateInput) {
                jsonMapper.readTree(data);
            }
            // 简化的JSON到CSV转换
            Object json = jsonMapper.readValue(data, Object.class);
            return convertJsonToCsv(json);
        }
        
        private String convertJsonToCsv(Object obj) {
            if (obj instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, Object> map = (Map<String, Object>) obj;
                StringBuilder csv = new StringBuilder();
                // 添加表头
                csv.append(String.join(",", map.keySet())).append("\n");
                // 添加数据行
                csv.append(String.join(",", map.values().stream().map(Object::toString).toArray(String[]::new)));
                return csv.toString();
            }
            return "value\n" + obj;
        }
    }

    /**
     * JSON到YAML转换器
     */
    public class JsonToYamlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            if (validateInput) {
                jsonMapper.readTree(data);
            }
            // 简化的JSON到YAML转换
            Object json = jsonMapper.readValue(data, Object.class);
            return convertJsonToYaml(json, 0);
        }
        
        private String convertJsonToYaml(Object obj, int indent) {
            String indentStr = "  ".repeat(indent);
            if (obj instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, Object> map = (Map<String, Object>) obj;
                StringBuilder yaml = new StringBuilder();
                for (Map.Entry<String, Object> entry : map.entrySet()) {
                    yaml.append(indentStr).append(entry.getKey()).append(": ");
                    if (entry.getValue() instanceof Map || entry.getValue() instanceof List) {
                        yaml.append("\n").append(convertJsonToYaml(entry.getValue(), indent + 1));
                    } else {
                        yaml.append(entry.getValue()).append("\n");
                    }
                }
                return yaml.toString();
            } else if (obj instanceof List) {
                @SuppressWarnings("unchecked")
                List<Object> list = (List<Object>) obj;
                StringBuilder yaml = new StringBuilder();
                for (Object item : list) {
                    yaml.append(indentStr).append("- ").append(item).append("\n");
                }
                return yaml.toString();
            }
            return indentStr + obj + "\n";
        }
    }

    /**
     * XML到JSON转换器
     */
    public class XmlToJsonConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 简化的XML到JSON转换
            Map<String, Object> json = convertXmlToJson(data);
            if (prettyPrint) {
                return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
            }
            return jsonMapper.writeValueAsString(json);
        }
        
        private Map<String, Object> convertXmlToJson(String xml) {
            Map<String, Object> result = new HashMap<>();
            // 简化的XML解析
            String content = xml.replaceAll("<[^>]+>", "").trim();
            result.put("content", content);
            return result;
        }
    }

    /**
     * XML到XML转换器
     */
    public class XmlToXmlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // XML到XML的转换主要是格式化和验证
            return data;
        }
    }

    /**
     * XML到CSV转换器
     */
    public class XmlToCsvConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 先转换为JSON，再转换为CSV
            JsonToCsvConverter jsonToCsv = new JsonToCsvConverter();
            XmlToJsonConverter xmlToJson = new XmlToJsonConverter();
            String jsonData = xmlToJson.convert(data);
            return jsonToCsv.convert(jsonData);
        }
    }

    /**
     * XML到YAML转换器
     */
    public class XmlToYamlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 先转换为JSON，再转换为YAML
            JsonToYamlConverter jsonToYaml = new JsonToYamlConverter();
            XmlToJsonConverter xmlToJson = new XmlToJsonConverter();
            String jsonData = xmlToJson.convert(data);
            return jsonToYaml.convert(jsonData);
        }
    }

    /**
     * CSV到JSON转换器
     */
    public class CsvToJsonConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // CSV转换需要更复杂的逻辑，这里简化处理
            Map<String, String> csvData = new HashMap<>();
            String[] lines = data.split("\n");
            if (lines.length > 0) {
                String[] headers = lines[0].split(",");
                for (int i = 1; i < lines.length; i++) {
                    String[] values = lines[i].split(",");
                    for (int j = 0; j < Math.min(headers.length, values.length); j++) {
                        csvData.put(headers[j].trim(), values[j].trim());
                    }
                }
            }
            if (prettyPrint) {
                return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(csvData);
            }
            return jsonMapper.writeValueAsString(csvData);
        }
    }

    /**
     * CSV到XML转换器
     */
    public class CsvToXmlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 先转换为JSON，再转换为XML
            CsvToJsonConverter csvToJson = new CsvToJsonConverter();
            String jsonData = csvToJson.convert(data);
            JsonToXmlConverter jsonToXml = new JsonToXmlConverter();
            return jsonToXml.convert(jsonData);
        }
    }

    /**
     * CSV到CSV转换器
     */
    public class CsvToCsvConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // CSV到CSV的转换主要是格式化和验证
            return data;
        }
    }

    /**
     * CSV到YAML转换器
     */
    public class CsvToYamlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 先转换为JSON，再转换为YAML
            CsvToJsonConverter csvToJson = new CsvToJsonConverter();
            String jsonData = csvToJson.convert(data);
            JsonToYamlConverter jsonToYaml = new JsonToYamlConverter();
            return jsonToYaml.convert(jsonData);
        }
    }

    /**
     * YAML到JSON转换器
     */
    public class YamlToJsonConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 简化的YAML到JSON转换
            Map<String, Object> json = convertYamlToJson(data);
            if (prettyPrint) {
                return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
            }
            return jsonMapper.writeValueAsString(json);
        }
        
        private Map<String, Object> convertYamlToJson(String yaml) {
            Map<String, Object> result = new HashMap<>();
            String[] lines = yaml.split("\n");
            for (String line : lines) {
                if (line.contains(":")) {
                    String[] parts = line.split(":", 2);
                    if (parts.length == 2) {
                        result.put(parts[0].trim(), parts[1].trim());
                    }
                }
            }
            return result;
        }
    }

    /**
     * YAML到XML转换器
     */
    public class YamlToXmlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 先转换为JSON，再转换为XML
            YamlToJsonConverter yamlToJson = new YamlToJsonConverter();
            String jsonData = yamlToJson.convert(data);
            JsonToXmlConverter jsonToXml = new JsonToXmlConverter();
            return jsonToXml.convert(jsonData);
        }
    }

    /**
     * YAML到CSV转换器
     */
    public class YamlToCsvConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // 先转换为JSON，再转换为CSV
            YamlToJsonConverter yamlToJson = new YamlToJsonConverter();
            String jsonData = yamlToJson.convert(data);
            JsonToCsvConverter jsonToCsv = new JsonToCsvConverter();
            return jsonToCsv.convert(jsonData);
        }
    }

    /**
     * YAML到YAML转换器
     */
    public class YamlToYamlConverter implements FormatConverter {
        @Override
        public String convert(String data) throws Exception {
            // YAML到YAML的转换主要是格式化和验证
            return data;
        }
    }

    /**
     * 转换结果类
     */
    public static class ConversionResult {
        private final String data;
        private final boolean success;
        private final String status;
        private final String errorMessage;

        public ConversionResult(String data, boolean success, String status, String errorMessage) {
            this.data = data;
            this.success = success;
            this.status = status;
            this.errorMessage = errorMessage;
        }

        // Getter方法
        public String getData() { return data; }
        public boolean isSuccess() { return success; }
        public String getStatus() { return status; }
        public String getErrorMessage() { return errorMessage; }
    }

    /**
     * 验证结果类
     */
    public static class ValidationResult {
        private final boolean valid;
        private final String status;
        private final String errorMessage;

        public ValidationResult(boolean valid, String status, String errorMessage) {
            this.valid = valid;
            this.status = status;
            this.errorMessage = errorMessage;
        }

        // Getter方法
        public boolean isValid() { return valid; }
        public String getStatus() { return status; }
        public String getErrorMessage() { return errorMessage; }
    }

    /**
     * 转换配置类
     */
    public static class ConversionConfig {
        private final String key;
        private final String inputFormat;
        private final String outputFormat;
        private final boolean prettyPrint;
        private final boolean validateInput;
        private final boolean validateOutput;

        public ConversionConfig(String key, String inputFormat, String outputFormat,
                              boolean prettyPrint, boolean validateInput, boolean validateOutput) {
            this.key = key;
            this.inputFormat = inputFormat;
            this.outputFormat = outputFormat;
            this.prettyPrint = prettyPrint;
            this.validateInput = validateInput;
            this.validateOutput = validateOutput;
        }

        // Getter方法
        public String getKey() { return key; }
        public String getInputFormat() { return inputFormat; }
        public String getOutputFormat() { return outputFormat; }
        public boolean isPrettyPrint() { return prettyPrint; }
        public boolean isValidateInput() { return validateInput; }
        public boolean isValidateOutput() { return validateOutput; }
    }

    /**
     * 转换统计信息类
     */
    public static class ConversionStatistics {
        private final long totalConversions;
        private final long totalSuccessfulConversions;
        private final long totalFailedConversions;
        private final long totalBytesProcessed;
        private final int activeConverters;
        private final int totalConfigs;
        private final boolean conversionEnabled;
        private final String defaultInputFormat;
        private final String defaultOutputFormat;
        private final boolean prettyPrint;
        private final boolean validateInput;
        private final boolean validateOutput;
        private final int maxConversionSize;
        private final long timestamp;

        public ConversionStatistics(long totalConversions, long totalSuccessfulConversions, long totalFailedConversions,
                                  long totalBytesProcessed, int activeConverters, int totalConfigs, boolean conversionEnabled,
                                  String defaultInputFormat, String defaultOutputFormat, boolean prettyPrint,
                                  boolean validateInput, boolean validateOutput, int maxConversionSize, long timestamp) {
            this.totalConversions = totalConversions;
            this.totalSuccessfulConversions = totalSuccessfulConversions;
            this.totalFailedConversions = totalFailedConversions;
            this.totalBytesProcessed = totalBytesProcessed;
            this.activeConverters = activeConverters;
            this.totalConfigs = totalConfigs;
            this.conversionEnabled = conversionEnabled;
            this.defaultInputFormat = defaultInputFormat;
            this.defaultOutputFormat = defaultOutputFormat;
            this.prettyPrint = prettyPrint;
            this.validateInput = validateInput;
            this.validateOutput = validateOutput;
            this.maxConversionSize = maxConversionSize;
            this.timestamp = timestamp;
        }

        // Getter方法
        public long getTotalConversions() { return totalConversions; }
        public long getTotalSuccessfulConversions() { return totalSuccessfulConversions; }
        public long getTotalFailedConversions() { return totalFailedConversions; }
        public long getTotalBytesProcessed() { return totalBytesProcessed; }
        public int getActiveConverters() { return activeConverters; }
        public int getTotalConfigs() { return totalConfigs; }
        public boolean isConversionEnabled() { return conversionEnabled; }
        public String getDefaultInputFormat() { return defaultInputFormat; }
        public String getDefaultOutputFormat() { return defaultOutputFormat; }
        public boolean isPrettyPrint() { return prettyPrint; }
        public boolean isValidateInput() { return validateInput; }
        public boolean isValidateOutput() { return validateOutput; }
        public int getMaxConversionSize() { return maxConversionSize; }
        public long getTimestamp() { return timestamp; }
        
        public double getSuccessRate() {
            return totalConversions > 0 ? (double) totalSuccessfulConversions / totalConversions : 0.0;
        }
        
        public double getFailureRate() {
            return totalConversions > 0 ? (double) totalFailedConversions / totalConversions : 0.0;
        }
    }
}